/*
 * @Description: 因子库列表
 * @Author: chenju
 * @Date: 2022-01-19 10:47:42
 * @LastEditors: qingyang
 * @LastEditTime: 2022-12-31 15:33:35
 */

import { get, post } from '@/utils/http'
import type { BasicPagingListParams, BasicPagingListResult } from '@/apis/basicModel'
import type {
  GetFactorListParams,
  GetFactorListResult,
  createFactorParams,
  updateStatusParams,
  batchUpdateStatusParams,
  getGWPResult
} from './model/factorListModel'
import baseConfig from '@/config'

enum Api {
  // 因子库列表分页查询
  GET_FACTOR_LIST = '/inventory/inventoryFactor/page',
  GET_VERSION_LIST = '/inventory/inventoryFactor/listVersion',
  CREATE_FACTOR = '/inventory/inventoryFactor/save',
  UPDATE_STATUS = '/inventory/inventoryFactor/updateStatus',
  BATCH_UPDATE_STATUS = '/inventory/inventoryFactor/batchUpdateStatus',
  GET_GWP_VERSION = '/inventory/inventoryFactor/getGwpVersion',
  GET_GWP = '/inventory/inventoryFactor/getGWP',
  GET_FACTOR = '/inventory/inventoryFactor/getFactor'
}

// 因子库列表分页查询
export const getFactorList = (
  params: GetFactorListParams & BasicPagingListParams
): Promise<BasicPagingListResult<GetFactorListResult>> => get(Api.GET_FACTOR_LIST, params)

export const getVersionList = (): Promise<any> => get(Api.GET_VERSION_LIST)

// 新建
export const createFactor = (params: createFactorParams): Promise<void> =>
  post(Api.CREATE_FACTOR, params)

// 修改因子状态
export const updateStatus = (params: updateStatusParams): Promise<void> =>
  post(Api.UPDATE_STATUS, params)

// 因子批量启用/停用
export const batchUpdateStatus = (params: batchUpdateStatusParams): Promise<void> =>
  post(Api.BATCH_UPDATE_STATUS, params)

export const uploadFilePostUrl = baseConfig.BASE_URL + '/inventory/inventoryFactor/import'

// gwp版本列表获取
export const getGwpVersion = (): Promise<any> => get(Api.GET_GWP_VERSION)

// 获取gwp版本的气体值
export const getGWP = (gwpVersion: string): Promise<getGWPResult> =>
  get(Api.GET_GWP, { gwpVersion })

// 详情
export const getFactor = (factorNo: string): Promise<any> => get(Api.GET_FACTOR, { factorNo })
